package com.vanke.devops.dal.util.collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ListUtils {
    public static <E> List<List<E>> split(List<E> elements, int pageSize) {
        if (CollectionUtils.isEmpty(elements)) {
            return Collections.EMPTY_LIST;
        }
        List<List<E>> result = new ArrayList<>();
        int index = 0;
        while (index < elements.size()) {
            int end = Math.min(index + pageSize, elements.size());
            result.add(elements.subList(index, end));
            index = end;
        }
        return result;
    }
}

